<template>
	<view class="container">
		<view class="uni-list">
			<navigator class="uni-list-cell uni-list-cell-pd" hover-class="none" v-for="(item, index) in list"
				:key="index" :url="'/pages/merchants/goods_detail/index?customerId=' + item.mainId">
				<image mode="widthFix" :src="item.focusImage !=  'null' || '../../../static/images/user_12.png'" class="pic"></image>
				<view class="uni-list-cell-db">
					<view class="uni-flex">
						<view class="uni-flex-item">{{item.focusName}}</view>
						<view :class="['focusBtn', item.isFocus == 'Y' ? 'border-green text-green' : ''] " @click.stop="focus(index, item.mainId, item.shareEvalType)"
							>{{item.isFocus == 'Y' ? '已关注' : '关注'}}</view>
					</view>
					<view class="p line1">{{item.focusRemark}}</view>
				</view>
			</navigator>
		</view>
		<view class="footer">
			<u-button type="primary" color="#06A972" text="我是批发商" @click="applySave"></u-button>
		</view>

	</view>
</template>


<script>
	export default {
		data() {
			return {
				list: []
			}

		},

		onLoad() {
			this.getMyFocus();
		},

		onShow() {
			this.getMyFocus();
		},

		methods: {

			getMyFocus() {
				let that = this;
				that.$request.get('share/myFocus', {
					userInfoId: that.$store.state.app.uid
				}).then(res => {
					that.list = res.value.list
				}).catch(err => {
					that.$util.Tips({
						title: err
					});
				})
			},
			
			focus(index, mainId, shareEvalType) {
				let that = this, url;
				if (that.list[index].isFocus == 'N') {
					that.list[index].isFocus = 'Y';
					url = 'share/focus'
				} else {
					that.list[index].isFocus = 'N';
					url = 'share/unFocus'
				}
				that.$request.get(url, {
					userInfoId: that.$store.state.app.uid,
					shareEvalType: shareEvalType,
					mainId: mainId
				}).then(res => {
					// that.list.splice(index, 1);
					if (that.list[index].isFocus == 'Y') {
						that.$util.Tips({
							title: '关注成功'
						})
					} else {
						that.$util.Tips({
							title: '关注已取消'
						})
					}
				}).catch(err => {
					that.$util.Tips({
						title: err
					})
				})
			},

			applySave() {
				uni.navigateTo({
					url: '/pages/merchants/apply_agent/index'
				});
			}
		}
	}
</script>

<style>
	.container {
		padding-bottom: calc(140rpx + constant(safe-area-inset-bottom));
		padding-bottom: calc(140rpx + env(safe-area-inset-bottom));
	}
	
	.container .pic {
		width: 166rpx;
		height: 200rpx;
		margin-right: 20rpx;
		border-radius: 20rpx;
	}

	.container .p {
		color: #BDBDBD;
		font-size: 22rpx;
		/* margin-top: 10rpx; */
		width: 560rpx;
	}

	.container .uni-flex {
		align-items: center;
		padding-bottom: 20rpx;
	}

	.container .uni-flex .uni-flex-item {
		font-weight: bold;
	}
</style>